import java.util.Arrays;
import java.util.HashMap;

/**
 * @author wangj881
 * @date 2024-12-05 19:06
 */
public class L1_2 {
    public static void main(String[] args) {
        int[] nums = {3, 2, 4};
        int target = 6;
        int[] ints = new Solution().twoSum(nums, target);
        System.out.println(Arrays.toString(ints));
    }

    static class Solution {
        public int[] twoSum(int[] nums, int target) {
            HashMap<Integer, Integer> map = new HashMap<>();
            int[] res = new int[2];
            for (int i = 0; i < nums.length; i++) {
                int j = target - nums[i];
                Integer index = map.getOrDefault(j, -1);
                if (index != -1) {
                    res[0] = index;
                    res[1] = i;
                    break;
                }
                map.put(nums[i], i);
            }
            return res;
        }
    }
}
